import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/layout/layout.vue'
import home from '@/views/layout/home.vue'
import category from '@/views/layout/category.vue'
import usercenter from '@/views/layout/usercenter.vue'
import cart from '@/views/layout/cart.vue'
import store from '@/store'

// 路由懒加载
const login = () =>
    import ('@/views/login/login.vue')
const pay = () =>
    import ('@/views/pay/pay-page.vue')
const payResult = () =>
    import ('@/views/pay/payResult.vue')
const confirmOrder = () =>
    import ('@/views/pay/confirmOrder.vue')
const myOrder = () =>
    import ('@/views/order/myorder.vue')
const ProductDetail = () =>
    import ('@/views/product/productdetail.vue')
const organDetail = () =>
    import ('@/views/product/organDetail.vue')
const screenCode = () =>
    import ('@/views/product/screenCode.vue')
const orderDetails = () =>
    import ('@/views/product/orderDetails.vue')
const SearchList = () =>
    import ('@/views/search/search-result.vue')
const Search = () =>
    import ('@/views/search/search-page.vue')
const useraddress = () =>
    import ('@/views/addresses/useraddress.vue')
const useraddressedit = () =>
    import ('@/views/addresses/useraddress-edit.vue')
const UserCollect = () =>
    import ('@/views/collect/usercollect.vue')
const ProductComment = () =>
    import ('@/views/order/product-comment.vue')
const ProductCommentDetail = () =>
    import ('@/views/order/product-comment-detail.vue')
    //打分看板
const ScoringBoard = () =>
    import ('@/scoring/scoringBoard/index.vue')
const shareBorad = () =>
    import ('@/scoring/scoringBoard/shareBorad.vue')
const scoreList = () =>
    import ('@/scoring/scoringBoard/scoreList.vue')
const scoring = () =>
    import ('@/scoring/home/homePage.vue')
const makeScore = () =>
    import ('@/scoring/makeScore/makeScore.vue')
const onlyOneMake = () =>
    import ('@/scoring/makeScore/onlyOneMake.vue')
const multipleOnlyOne = () =>
    import ('@/scoring/makeScore/multipleOnlyOne.vue')
const makeIndex = () =>
    import ('@/scoring/makeScore/makeIndex.vue')
const makeScoreMultiple = () =>
    import ('@/scoring/makeScore/makeScoreMultiple.vue')
    // 登录页面
const loginIndexScore = () =>
    import ('@/scoring/loginIndex/loginIndex.vue')
const getCodeScore = () =>
    import ('@/scoring/loginIndex/getCode.vue')
const inputCodeScore = () =>
    import ('@/scoring/loginIndex/inputCode.vue')
    // 登录页面
const loginIndexAdmin = () =>
    import ('@/scoring/loginIndexAdmin/loginIndex.vue')
const getCodeAdmin = () =>
    import ('@/scoring/loginIndexAdmin/getCode.vue')
const inputCodeAdmin = () =>
    import ('@/scoring/loginIndexAdmin/inputCode.vue')
    // 购票登录页面
const loginIndexTicketing = () =>
    import ('@/scoring/loginIndexTicketing/loginIndex.vue')
const getCodeTicketing = () =>
    import ('@/scoring/loginIndexTicketing/getCode.vue')
const inputCodeTicketing = () =>
    import ('@/scoring/loginIndexTicketing/inputCode.vue')
Vue.use(VueRouter)

const router = new VueRouter({
    base: '/',
    // mode: 'history',
    routes: [{
            path: '/',
            component: Layout,
            redirect: '/home',
            children: [{
                    path: '/home',
                    component: home
                }, {
                    path: '/category',
                    component: category
                }, {
                    path: '/user',
                    component: usercenter
                }, {
                    path: '/cart',
                    component: cart
                },
                {
                    path: '/useraddress',
                    component: useraddress
                },
                {
                    path: '/useraddressedit',
                    component: useraddressedit
                }
            ]
        },
        // {
        //     path: '/login',
        //     component: login
        // },
        {
            path: '/confirmOrder',
            component: confirmOrder
        },
        {
            path: '/pay',
            component: pay
        },
        {
            path: '/payResult',
            component: payResult
        },
        {
            path: '/order',
            component: myOrder
        },
        {
            path: '/prodetail/:productid',
            component: ProductDetail
        },
        {
            path: '/organDetail',
            component: organDetail
        },
        {
            path: '/screenCode',
            component: screenCode
        },
        {
            path: '/orderDetails',
            component: orderDetails
        },
        {
            path: '/search_list',
            component: SearchList
        },
        {
            path: '/search',
            component: Search
        },
        {
            path: '/usercollect',
            component: UserCollect
        },
        {
            path: '/productcomment',
            component: ProductComment
        },
        {
            path: '/procomment-detail',
            component: ProductCommentDetail
        },
        {
            path: '/scoring/scoringBoard',
            name: 'scoringBoard',
            component: ScoringBoard
        },
        {
            path: '/scoring/home',
            component: scoring
        },
        {
            path: '/scoring/shareBorad',
            component: shareBorad
        },
        {
            path: '/scoring/scoreList',
            component: scoreList
        },
        {
            path: '/scoring/makeScore',
            component: makeScore
        },
        {
            path: '/scoring/onlyOneMake',
            component: onlyOneMake
        },
        {
            path: '/scoring/multipleOnlyOne',
            component: multipleOnlyOne
        },
        {
            path: '/scoring/makeIndex',
            component: makeIndex
        },
        {
            path: '/scoring/makeScoreMultiple',
            component: makeScoreMultiple
        },
        // 打分登录
        {
            path: '/scoring/loginIndex',
            component: loginIndexScore
        },
        {
            path: '/scoring/getCode',
            component: getCodeScore
        },
        {
            path: '/scoring/inputCode',
            component: inputCodeScore
        },
        // 主办方登录
        {
            path: '/admin/loginIndex',
            component: loginIndexAdmin
        },
        {
            path: '/admin/getCode',
            component: getCodeAdmin
        },
        {
            path: '/admin/inputCode',
            component: inputCodeAdmin
        },
        // 购票登录
        {
            path: '/ticketing/loginIndex',
            component: loginIndexTicketing
        },
        {
            path: '/ticketing/getCode',
            component: getCodeTicketing
        },
        {
            path: '/ticketing/inputCode',
            component: inputCodeTicketing
        },
    ]
})

const needLoginUrl = ['/pay', '/order']
router.beforeEach((to, from, next) => {
    // 判断路由路径是否在需要登录的路径数组中
    // if (needLoginUrl.includes(to.path)) {
    //   // 是需要登录后才能访问的页面，则判断是否有token，没有token直接跳转到/login页面
    //   if (!store.state.user.userinfo.token) {
    //     next('/login')
    //   }
    // }
    next()
})
export default router